package com.wanmait.recruitment.webController;

import com.wanmait.recruitment.pojo.Company;
import com.wanmait.recruitment.service.CompanyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class WebSearchController {
    @Resource
    private CompanyService companyService;
    @PostMapping("SearchList")
    public ModelAndView search(String type, String kd){
        ModelAndView modelAndView = new ModelAndView();
        if ("company".equals(type)){
            //模糊搜索

            List<Company> companies = companyService.companySearchJudge(kd);
            if (kd==""){
                //查出所有公司所有数据
                List<Company> companies1 = companyService.findAll();
                System.out.println("所有的");
                modelAndView.addObject("companies1",companies1);
                modelAndView.setViewName("zhuang/companylist");
                return modelAndView;
            }
            else {
                String name = null;
                for (Company company1:companies){
                    if (company1.getCompanyName().equals(kd)){
                        Company company = companyService.companySearch(company1.getCompanyName());
                        System.out.println(company1.getCompanyName());
                        modelAndView.addObject("company",company);
                        modelAndView.setViewName("zhuang/companylist");
                        return modelAndView;
                    }
                    for (Company company:companies){
                        System.out.println(company.getCompanyName());
                    }
                    System.out.println(company1.getCompanyName());
                    modelAndView.addObject("companies",companies);
                    modelAndView.setViewName("zhuang/companylist");
                    return modelAndView;
                }
            }
        }
        return null;
    }

}
